Passed
Pull Request — master (#47)
by
unknown
05:23
created

modal.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap modal.js v4.6.0 (https://getbootstrap.com/)
3
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './util'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Modal = factory(global.jQuery, global.Util));
0 ignored issues
show
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, (function ($, Util) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
16
17
  function _defineProperties(target, props) {
18
    for (var i = 0; i < props.length; i++) {
19
      var descriptor = props[i];
20
      descriptor.enumerable = descriptor.enumerable || false;
21
      descriptor.configurable = true;
22
      if ("value" in descriptor) descriptor.writable = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
23
      Object.defineProperty(target, descriptor.key, descriptor);
24
    }
25
  }
26
27
  function _createClass(Constructor, protoProps, staticProps) {
28
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
29
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
30
    return Constructor;
31
  }
32
33
  function _extends() {
34
    _extends = Object.assign || function (target) {
0 ignored issues
show
Comprehensibility introduced by
It seems like you are trying to overwrite a function name here. _extends is already defined in line 33 as a function. While this will work, it can be very confusing.
Loading history...
35
      for (var i = 1; i < arguments.length; i++) {
36
        var source = arguments[i];
37
38
        for (var key in source) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
39
          if (Object.prototype.hasOwnProperty.call(source, key)) {
40
            target[key] = source[key];
41
          }
42
        }
43
      }
44
45
      return target;
46
    };
47
48
    return _extends.apply(this, arguments);
49
  }
50
51
  /**
52
   * ------------------------------------------------------------------------
53
   * Constants
54
   * ------------------------------------------------------------------------
55
   */
56
57
  var NAME = 'modal';
58
  var VERSION = '4.6.0';
59
  var DATA_KEY = 'bs.modal';
60
  var EVENT_KEY = "." + DATA_KEY;
61
  var DATA_API_KEY = '.data-api';
62
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
63
  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
64
65
  var Default = {
66
    backdrop: true,
67
    keyboard: true,
68
    focus: true,
69
    show: true
70
  };
71
  var DefaultType = {
72
    backdrop: '(boolean|string)',
73
    keyboard: 'boolean',
74
    focus: 'boolean',
75
    show: 'boolean'
76
  };
77
  var EVENT_HIDE = "hide" + EVENT_KEY;
78
  var EVENT_HIDE_PREVENTED = "hidePrevented" + EVENT_KEY;
79
  var EVENT_HIDDEN = "hidden" + EVENT_KEY;
80
  var EVENT_SHOW = "show" + EVENT_KEY;
81
  var EVENT_SHOWN = "shown" + EVENT_KEY;
82
  var EVENT_FOCUSIN = "focusin" + EVENT_KEY;
83
  var EVENT_RESIZE = "resize" + EVENT_KEY;
84
  var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY;
85
  var EVENT_KEYDOWN_DISMISS = "keydown.dismiss" + EVENT_KEY;
86
  var EVENT_MOUSEUP_DISMISS = "mouseup.dismiss" + EVENT_KEY;
87
  var EVENT_MOUSEDOWN_DISMISS = "mousedown.dismiss" + EVENT_KEY;
88
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
89
  var CLASS_NAME_SCROLLABLE = 'modal-dialog-scrollable';
90
  var CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure';
91
  var CLASS_NAME_BACKDROP = 'modal-backdrop';
92
  var CLASS_NAME_OPEN = 'modal-open';
93
  var CLASS_NAME_FADE = 'fade';
94
  var CLASS_NAME_SHOW = 'show';
95
  var CLASS_NAME_STATIC = 'modal-static';
96
  var SELECTOR_DIALOG = '.modal-dialog';
97
  var SELECTOR_MODAL_BODY = '.modal-body';
98
  var SELECTOR_DATA_TOGGLE = '[data-toggle="modal"]';
99
  var SELECTOR_DATA_DISMISS = '[data-dismiss="modal"]';
100
  var SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
101
  var SELECTOR_STICKY_CONTENT = '.sticky-top';
102
  /**
103
   * ------------------------------------------------------------------------
104
   * Class Definition
105
   * ------------------------------------------------------------------------
106
   */
107
108
  var Modal = /*#__PURE__*/function () {
109
    function Modal(element, config) {
110
      this._config = this._getConfig(config);
111
      this._element = element;
112
      this._dialog = element.querySelector(SELECTOR_DIALOG);
113
      this._backdrop = null;
114
      this._isShown = false;
115
      this._isBodyOverflowing = false;
116
      this._ignoreBackdropClick = false;
117
      this._isTransitioning = false;
118
      this._scrollbarWidth = 0;
119
    } // Getters
120
121
122
    var _proto = Modal.prototype;
123
124
    // Public
125
    _proto.toggle = function toggle(relatedTarget) {
126
      return this._isShown ? this.hide() : this.show(relatedTarget);
127
    };
128
129
    _proto.show = function show(relatedTarget) {
130
      var _this = this;
131
132
      if (this._isShown || this._isTransitioning) {
133
        return;
134
      }
135
136
      if ($__default['default'](this._element).hasClass(CLASS_NAME_FADE)) {
137
        this._isTransitioning = true;
138
      }
139
140
      var showEvent = $__default['default'].Event(EVENT_SHOW, {
141
        relatedTarget: relatedTarget
142
      });
143
      $__default['default'](this._element).trigger(showEvent);
144
145
      if (this._isShown || showEvent.isDefaultPrevented()) {
146
        return;
147
      }
148
149
      this._isShown = true;
150
151
      this._checkScrollbar();
152
153
      this._setScrollbar();
154
155
      this._adjustDialog();
156
157
      this._setEscapeEvent();
158
159
      this._setResizeEvent();
160
161
      $__default['default'](this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function (event) {
162
        return _this.hide(event);
163
      });
164
      $__default['default'](this._dialog).on(EVENT_MOUSEDOWN_DISMISS, function () {
165
        $__default['default'](_this._element).one(EVENT_MOUSEUP_DISMISS, function (event) {
166
          if ($__default['default'](event.target).is(_this._element)) {
167
            _this._ignoreBackdropClick = true;
168
          }
169
        });
170
      });
171
172
      this._showBackdrop(function () {
173
        return _this._showElement(relatedTarget);
174
      });
175
    };
176
177
    _proto.hide = function hide(event) {
178
      var _this2 = this;
179
180
      if (event) {
181
        event.preventDefault();
182
      }
183
184
      if (!this._isShown || this._isTransitioning) {
185
        return;
186
      }
187
188
      var hideEvent = $__default['default'].Event(EVENT_HIDE);
189
      $__default['default'](this._element).trigger(hideEvent);
190
191
      if (!this._isShown || hideEvent.isDefaultPrevented()) {
192
        return;
193
      }
194
195
      this._isShown = false;
196
      var transition = $__default['default'](this._element).hasClass(CLASS_NAME_FADE);
197
198
      if (transition) {
199
        this._isTransitioning = true;
200
      }
201
202
      this._setEscapeEvent();
203
204
      this._setResizeEvent();
205
206
      $__default['default'](document).off(EVENT_FOCUSIN);
207
      $__default['default'](this._element).removeClass(CLASS_NAME_SHOW);
208
      $__default['default'](this._element).off(EVENT_CLICK_DISMISS);
209
      $__default['default'](this._dialog).off(EVENT_MOUSEDOWN_DISMISS);
210
211
      if (transition) {
212
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this._element);
213
        $__default['default'](this._element).one(Util__default['default'].TRANSITION_END, function (event) {
214
          return _this2._hideModal(event);
215
        }).emulateTransitionEnd(transitionDuration);
216
      } else {
217
        this._hideModal();
218
      }
219
    };
220
221
    _proto.dispose = function dispose() {
222
      [window, this._element, this._dialog].forEach(function (htmlElement) {
223
        return $__default['default'](htmlElement).off(EVENT_KEY);
224
      });
225
      /**
226
       * `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
227
       * Do not move `document` in `htmlElements` array
228
       * It will remove `EVENT_CLICK_DATA_API` event that should remain
229
       */
230
231
      $__default['default'](document).off(EVENT_FOCUSIN);
232
      $__default['default'].removeData(this._element, DATA_KEY);
233
      this._config = null;
234
      this._element = null;
235
      this._dialog = null;
236
      this._backdrop = null;
237
      this._isShown = null;
238
      this._isBodyOverflowing = null;
239
      this._ignoreBackdropClick = null;
240
      this._isTransitioning = null;
241
      this._scrollbarWidth = null;
242
    };
243
244
    _proto.handleUpdate = function handleUpdate() {
245
      this._adjustDialog();
246
    } // Private
247
    ;
248
249
    _proto._getConfig = function _getConfig(config) {
250
      config = _extends({}, Default, config);
251
      Util__default['default'].typeCheckConfig(NAME, config, DefaultType);
252
      return config;
253
    };
254
255
    _proto._triggerBackdropTransition = function _triggerBackdropTransition() {
256
      var _this3 = this;
257
258
      var hideEventPrevented = $__default['default'].Event(EVENT_HIDE_PREVENTED);
259
      $__default['default'](this._element).trigger(hideEventPrevented);
260
261
      if (hideEventPrevented.isDefaultPrevented()) {
262
        return;
263
      }
264
265
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
266
267
      if (!isModalOverflowing) {
268
        this._element.style.overflowY = 'hidden';
269
      }
270
271
      this._element.classList.add(CLASS_NAME_STATIC);
272
273
      var modalTransitionDuration = Util__default['default'].getTransitionDurationFromElement(this._dialog);
274
      $__default['default'](this._element).off(Util__default['default'].TRANSITION_END);
275
      $__default['default'](this._element).one(Util__default['default'].TRANSITION_END, function () {
276
        _this3._element.classList.remove(CLASS_NAME_STATIC);
277
278
        if (!isModalOverflowing) {
279
          $__default['default'](_this3._element).one(Util__default['default'].TRANSITION_END, function () {
280
            _this3._element.style.overflowY = '';
281
          }).emulateTransitionEnd(_this3._element, modalTransitionDuration);
282
        }
283
      }).emulateTransitionEnd(modalTransitionDuration);
284
285
      this._element.focus();
286
    };
287
288
    _proto._showElement = function _showElement(relatedTarget) {
289
      var _this4 = this;
290
291
      var transition = $__default['default'](this._element).hasClass(CLASS_NAME_FADE);
292
      var modalBody = this._dialog ? this._dialog.querySelector(SELECTOR_MODAL_BODY) : null;
293
294
      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
0 ignored issues
show
Bug introduced by
The variable Node seems to be never declared. If this is a global, consider adding a /** global: Node */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
295
        // Don't move modal's DOM position
296
        document.body.appendChild(this._element);
297
      }
298
299
      this._element.style.display = 'block';
300
301
      this._element.removeAttribute('aria-hidden');
302
303
      this._element.setAttribute('aria-modal', true);
304
305
      this._element.setAttribute('role', 'dialog');
306
307
      if ($__default['default'](this._dialog).hasClass(CLASS_NAME_SCROLLABLE) && modalBody) {
308
        modalBody.scrollTop = 0;
309
      } else {
310
        this._element.scrollTop = 0;
311
      }
312
313
      if (transition) {
314
        Util__default['default'].reflow(this._element);
315
      }
316
317
      $__default['default'](this._element).addClass(CLASS_NAME_SHOW);
318
319
      if (this._config.focus) {
320
        this._enforceFocus();
321
      }
322
323
      var shownEvent = $__default['default'].Event(EVENT_SHOWN, {
324
        relatedTarget: relatedTarget
325
      });
326
327
      var transitionComplete = function transitionComplete() {
328
        if (_this4._config.focus) {
329
          _this4._element.focus();
330
        }
331
332
        _this4._isTransitioning = false;
333
        $__default['default'](_this4._element).trigger(shownEvent);
334
      };
335
336
      if (transition) {
337
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this._dialog);
338
        $__default['default'](this._dialog).one(Util__default['default'].TRANSITION_END, transitionComplete).emulateTransitionEnd(transitionDuration);
339
      } else {
340
        transitionComplete();
341
      }
342
    };
343
344
    _proto._enforceFocus = function _enforceFocus() {
345
      var _this5 = this;
346
347
      $__default['default'](document).off(EVENT_FOCUSIN) // Guard against infinite focus loop
348
      .on(EVENT_FOCUSIN, function (event) {
349
        if (document !== event.target && _this5._element !== event.target && $__default['default'](_this5._element).has(event.target).length === 0) {
350
          _this5._element.focus();
351
        }
352
      });
353
    };
354
355
    _proto._setEscapeEvent = function _setEscapeEvent() {
356
      var _this6 = this;
357
358
      if (this._isShown) {
359
        $__default['default'](this._element).on(EVENT_KEYDOWN_DISMISS, function (event) {
360
          if (_this6._config.keyboard && event.which === ESCAPE_KEYCODE) {
361
            event.preventDefault();
362
363
            _this6.hide();
364
          } else if (!_this6._config.keyboard && event.which === ESCAPE_KEYCODE) {
365
            _this6._triggerBackdropTransition();
366
          }
367
        });
368
      } else if (!this._isShown) {
369
        $__default['default'](this._element).off(EVENT_KEYDOWN_DISMISS);
370
      }
371
    };
372
373
    _proto._setResizeEvent = function _setResizeEvent() {
374
      var _this7 = this;
375
376
      if (this._isShown) {
377
        $__default['default'](window).on(EVENT_RESIZE, function (event) {
378
          return _this7.handleUpdate(event);
379
        });
380
      } else {
381
        $__default['default'](window).off(EVENT_RESIZE);
382
      }
383
    };
384
385
    _proto._hideModal = function _hideModal() {
386
      var _this8 = this;
387
388
      this._element.style.display = 'none';
389
390
      this._element.setAttribute('aria-hidden', true);
391
392
      this._element.removeAttribute('aria-modal');
393
394
      this._element.removeAttribute('role');
395
396
      this._isTransitioning = false;
397
398
      this._showBackdrop(function () {
399
        $__default['default'](document.body).removeClass(CLASS_NAME_OPEN);
400
401
        _this8._resetAdjustments();
402
403
        _this8._resetScrollbar();
404
405
        $__default['default'](_this8._element).trigger(EVENT_HIDDEN);
406
      });
407
    };
408
409
    _proto._removeBackdrop = function _removeBackdrop() {
410
      if (this._backdrop) {
411
        $__default['default'](this._backdrop).remove();
412
        this._backdrop = null;
413
      }
414
    };
415
416
    _proto._showBackdrop = function _showBackdrop(callback) {
417
      var _this9 = this;
418
419
      var animate = $__default['default'](this._element).hasClass(CLASS_NAME_FADE) ? CLASS_NAME_FADE : '';
420
421
      if (this._isShown && this._config.backdrop) {
422
        this._backdrop = document.createElement('div');
423
        this._backdrop.className = CLASS_NAME_BACKDROP;
424
425
        if (animate) {
426
          this._backdrop.classList.add(animate);
427
        }
428
429
        $__default['default'](this._backdrop).appendTo(document.body);
430
        $__default['default'](this._element).on(EVENT_CLICK_DISMISS, function (event) {
431
          if (_this9._ignoreBackdropClick) {
432
            _this9._ignoreBackdropClick = false;
433
            return;
434
          }
435
436
          if (event.target !== event.currentTarget) {
437
            return;
438
          }
439
440
          if (_this9._config.backdrop === 'static') {
441
            _this9._triggerBackdropTransition();
442
          } else {
443
            _this9.hide();
444
          }
445
        });
446
447
        if (animate) {
448
          Util__default['default'].reflow(this._backdrop);
449
        }
450
451
        $__default['default'](this._backdrop).addClass(CLASS_NAME_SHOW);
452
453
        if (!callback) {
454
          return;
455
        }
456
457
        if (!animate) {
458
          callback();
459
          return;
460
        }
461
462
        var backdropTransitionDuration = Util__default['default'].getTransitionDurationFromElement(this._backdrop);
463
        $__default['default'](this._backdrop).one(Util__default['default'].TRANSITION_END, callback).emulateTransitionEnd(backdropTransitionDuration);
464
      } else if (!this._isShown && this._backdrop) {
465
        $__default['default'](this._backdrop).removeClass(CLASS_NAME_SHOW);
466
467
        var callbackRemove = function callbackRemove() {
468
          _this9._removeBackdrop();
469
470
          if (callback) {
471
            callback();
472
          }
473
        };
474
475
        if ($__default['default'](this._element).hasClass(CLASS_NAME_FADE)) {
476
          var _backdropTransitionDuration = Util__default['default'].getTransitionDurationFromElement(this._backdrop);
477
478
          $__default['default'](this._backdrop).one(Util__default['default'].TRANSITION_END, callbackRemove).emulateTransitionEnd(_backdropTransitionDuration);
479
        } else {
480
          callbackRemove();
481
        }
482
      } else if (callback) {
483
        callback();
484
      }
485
    } // ----------------------------------------------------------------------
486
    // the following methods are used to handle overflowing modals
487
    // todo (fat): these should probably be refactored out of modal.js
488
    // ----------------------------------------------------------------------
489
    ;
490
491
    _proto._adjustDialog = function _adjustDialog() {
492
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
493
494
      if (!this._isBodyOverflowing && isModalOverflowing) {
495
        this._element.style.paddingLeft = this._scrollbarWidth + "px";
496
      }
497
498
      if (this._isBodyOverflowing && !isModalOverflowing) {
499
        this._element.style.paddingRight = this._scrollbarWidth + "px";
500
      }
501
    };
502
503
    _proto._resetAdjustments = function _resetAdjustments() {
504
      this._element.style.paddingLeft = '';
505
      this._element.style.paddingRight = '';
506
    };
507
508
    _proto._checkScrollbar = function _checkScrollbar() {
509
      var rect = document.body.getBoundingClientRect();
510
      this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth;
511
      this._scrollbarWidth = this._getScrollbarWidth();
512
    };
513
514
    _proto._setScrollbar = function _setScrollbar() {
515
      var _this10 = this;
516
517
      if (this._isBodyOverflowing) {
518
        // Note: DOMNode.style.paddingRight returns the actual value or '' if not set
519
        //   while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
520
        var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT));
521
        var stickyContent = [].slice.call(document.querySelectorAll(SELECTOR_STICKY_CONTENT)); // Adjust fixed content padding
522
523
        $__default['default'](fixedContent).each(function (index, element) {
524
          var actualPadding = element.style.paddingRight;
525
          var calculatedPadding = $__default['default'](element).css('padding-right');
526
          $__default['default'](element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this10._scrollbarWidth + "px");
527
        }); // Adjust sticky content margin
528
529
        $__default['default'](stickyContent).each(function (index, element) {
530
          var actualMargin = element.style.marginRight;
531
          var calculatedMargin = $__default['default'](element).css('margin-right');
532
          $__default['default'](element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this10._scrollbarWidth + "px");
533
        }); // Adjust body padding
534
535
        var actualPadding = document.body.style.paddingRight;
536
        var calculatedPadding = $__default['default'](document.body).css('padding-right');
537
        $__default['default'](document.body).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + "px");
538
      }
539
540
      $__default['default'](document.body).addClass(CLASS_NAME_OPEN);
541
    };
542
543
    _proto._resetScrollbar = function _resetScrollbar() {
544
      // Restore fixed content padding
545
      var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT));
546
      $__default['default'](fixedContent).each(function (index, element) {
547
        var padding = $__default['default'](element).data('padding-right');
548
        $__default['default'](element).removeData('padding-right');
549
        element.style.paddingRight = padding ? padding : '';
550
      }); // Restore sticky content
551
552
      var elements = [].slice.call(document.querySelectorAll("" + SELECTOR_STICKY_CONTENT));
553
      $__default['default'](elements).each(function (index, element) {
554
        var margin = $__default['default'](element).data('margin-right');
555
556
        if (typeof margin !== 'undefined') {
557
          $__default['default'](element).css('margin-right', margin).removeData('margin-right');
558
        }
559
      }); // Restore body padding
560
561
      var padding = $__default['default'](document.body).data('padding-right');
562
      $__default['default'](document.body).removeData('padding-right');
563
      document.body.style.paddingRight = padding ? padding : '';
564
    };
565
566
    _proto._getScrollbarWidth = function _getScrollbarWidth() {
567
      // thx d.walsh
568
      var scrollDiv = document.createElement('div');
569
      scrollDiv.className = CLASS_NAME_SCROLLBAR_MEASURER;
570
      document.body.appendChild(scrollDiv);
571
      var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
572
      document.body.removeChild(scrollDiv);
573
      return scrollbarWidth;
574
    } // Static
575
    ;
576
577
    Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) {
578
      return this.each(function () {
579
        var data = $__default['default'](this).data(DATA_KEY);
580
581
        var _config = _extends({}, Default, $__default['default'](this).data(), typeof config === 'object' && config ? config : {});
582
583
        if (!data) {
584
          data = new Modal(this, _config);
585
          $__default['default'](this).data(DATA_KEY, data);
586
        }
587
588
        if (typeof config === 'string') {
589
          if (typeof data[config] === 'undefined') {
590
            throw new TypeError("No method named \"" + config + "\"");
591
          }
592
593
          data[config](relatedTarget);
594
        } else if (_config.show) {
595
          data.show(relatedTarget);
596
        }
597
      });
598
    };
599
600
    _createClass(Modal, null, [{
601
      key: "VERSION",
602
      get: function get() {
603
        return VERSION;
604
      }
605
    }, {
606
      key: "Default",
607
      get: function get() {
608
        return Default;
609
      }
610
    }]);
611
612
    return Modal;
613
  }();
614
  /**
615
   * ------------------------------------------------------------------------
616
   * Data Api implementation
617
   * ------------------------------------------------------------------------
618
   */
619
620
621
  $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
622
    var _this11 = this;
623
624
    var target;
625
    var selector = Util__default['default'].getSelectorFromElement(this);
626
627
    if (selector) {
628
      target = document.querySelector(selector);
629
    }
630
631
    var config = $__default['default'](target).data(DATA_KEY) ? 'toggle' : _extends({}, $__default['default'](target).data(), $__default['default'](this).data());
0 ignored issues
show
Bug introduced by
The variable target does not seem to be initialized in case selector on line 627 is false. Are you sure this can never be the case?
Loading history...
632
633
    if (this.tagName === 'A' || this.tagName === 'AREA') {
634
      event.preventDefault();
635
    }
636
637
    var $target = $__default['default'](target).one(EVENT_SHOW, function (showEvent) {
638
      if (showEvent.isDefaultPrevented()) {
639
        // Only register focus restorer if modal will actually get shown
640
        return;
641
      }
642
643
      $target.one(EVENT_HIDDEN, function () {
644
        if ($__default['default'](_this11).is(':visible')) {
645
          _this11.focus();
646
        }
647
      });
648
    });
649
650
    Modal._jQueryInterface.call($__default['default'](target), config, this);
651
  });
652
  /**
653
   * ------------------------------------------------------------------------
654
   * jQuery
655
   * ------------------------------------------------------------------------
656
   */
657
658
  $__default['default'].fn[NAME] = Modal._jQueryInterface;
659
  $__default['default'].fn[NAME].Constructor = Modal;
660
661
  $__default['default'].fn[NAME].noConflict = function () {
662
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
663
    return Modal._jQueryInterface;
664
  };
665
666
  return Modal;
667
668
})));
669
//# sourceMappingURL=modal.js.map
670